package com.sms.plateform.web.controller;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sms.plateform.common.finals.Constants;
import com.sms.plateform.common.util.JSONUtil;
import com.sms.plateform.common.util.Utils;
import com.sms.plateform.kernel.entity.UserInfo;
import com.sms.plateform.kernel.service.IMainRaskService;

/**
 * 主任务控制--既短信发送中心
 * @author yangru
 *
 */
@Controller
public class MainRaskController extends BaseController {
	
	@Autowired
	private IMainRaskService mainRaskService;
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/smsbatchsend_main")
	public String mainSendBatchSmsHandel(HttpServletRequest request,HttpServletResponse response,ModelMap model) {
		try {
			UserInfo userInfo=this.getUserInfo(request);
			String action=this.getUrlParam(request, "action");
			if("do".equals(action)){
				String mobiles=this.getUrlParam(request, "mobiles");
				String contents=this.getUrlParam(request, "contents");
				int stype=Integer.parseInt(Utils.trim(this.getUrlParam(request, "stype")));
				String sendtime=this.getUrlParam(request, "sendtime");
				int priority=Integer.parseInt(Utils.trim(this.getUrlParam(request, "priority")));
				int uid=Integer.parseInt(Utils.trim(this.getUrlParam(request, "id")));
				int result=this.mainRaskService.sendBatchMessage(uid, stype, sendtime,priority, mobiles, contents);
				try {
					response.getWriter().write(JSONUtil.object2json(result));
					return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			model.put("gid", userInfo.getGid());
			model.put("id", userInfo.getId());
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return "rask/smsbatchsend_main";
	}
}
